//
//  UITextField+GYCursorPosition.m
//  LockManagement
//
//  Created by apple on 2018/7/26.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "UITextField+GYCursorPosition.h"
#import <objc/runtime.h>

static NSString *Position = @"Position";

@implementation UITextField (GYCursorPosition)

- (void)setCursorPosition:(CGFloat)CursorPosition {
    //1.设置属性
    objc_setAssociatedObject(self, &Position, @(CursorPosition), OBJC_ASSOCIATION_ASSIGN);
    
    //2.设置UITextFeled的光标位置
    UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(0,0,CursorPosition,self.frame.size.height)];
    leftView.backgroundColor = [UIColor clearColor];
    self.leftView = leftView;
    self.leftViewMode = UITextFieldViewModeAlways;
    
}

- (CGFloat)CursorPosition {
    id value = objc_getAssociatedObject(self, &Position);
    
    return [value floatValue];
}
@end
